/**
 * 日期格式化
 * @author Thousand-paper-crane
 * @param {Number} yearate 
 * @param {Number} monthDate 
 * @param {Number} dayhDate 
 * @param {Number} hoursDate 
 * @param {Number} minutesDate 
 * @param {Number} secondDate 
 * @returns String
 */
function time(yearate,monthDate,dayhDate,hoursDate,minutesDate,secondDate){
    var nowDate = (new Date).getTime()
    var oldDate = new Date(yearate+'-'+monthDate+'-'+dayhDate+' '+hoursDate+':'+minutesDate+':'+secondDate).getTime()
    var chaDate = nowDate-oldDate
    if(parseInt(chaDate/1000/60/60/24)>=1){
        result =parseInt(chaDate/1000/60/60/24)+'天前'
    }else if(parseInt(chaDate/1000/60/60)>=1){
        result =parseInt(chaDate/1000/60/60)+'小时前'
    }else if(parseInt(chaDate/1000/60)>=1){
        result =parseInt(chaDate/1000/60)+'分钟前'
    }else if(parseInt(chaDate/1000)>=1){
        result ='刚刚'
    }else{
        alert('请输入有效日期')
    }
    return result
}
var dateTime=time(2021,11,26,13,12,00)
alert(dateTime)


/**
 * 判断浏览器内核
 * @author Thousand-paper-crane
 * @returns undefined
 */
function liulanqi() {
    var u = navigator.userAgent;
    return {
            trident: u.indexOf('Trident') > -1, //IE内核
            presto: u.indexOf('Presto') > -1, //opera内核
            webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
            gecko: u.indexOf('Firefox') > -1, //火狐内核Gecko
            mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
            ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios
            android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android
            iPhone: u.indexOf('iPhone') > -1 , //iPhone
            iPad: u.indexOf('iPad') > -1, //iPad
            webApp: u.indexOf('Safari') > -1 //Safari
        }
    }
console.log(liulanqi())


/**
 * 判断是pc端还是移动端
 * @author Thousand-paper-crane
 * @returns undefined
 */
function pmDate() {
    if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
        // window.location.href="你的手机版地址";
        alert("mobile")
    }
    else {
        // window.location.href="你的电脑版地址";
        alert("pc")
    }
}
pmDate();


/**
 * 判断是否是微信浏览器
 * @author Thousand-paper-crane
 * @returns undefined
 */
function is_weixn(){
    var ua = navigator.userAgent.toLowerCase();
    if(ua.match(/MicroMessenger/i)=="micromessenger") {
        return true;
    } else {
        return false;
    }
}
alert(is_weixn())